﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Resources;

namespace Luna.Framework.Impl.UriResolvers {
	public class ResourceUriResolver: IUriResolver {

		public bool supportScheme(string scheme) {
			return "res".Equals(scheme) || "resource".Equals(scheme);
		}

		public object resolveObject(IAppContext context, Uri uri, object data) {
			if (supportScheme(uri.Scheme)) {
				string asmName = uri.Host;
				string @namespace = uri.Segments[1].Substring(0, uri.Segments[1].Length - 1);
				string resName = uri.Segments[2];

				string typeName = @namespace + ", " + asmName;
				ResourceManager resMan = new ResourceManager(Type.GetType(typeName, true));
				return resMan.GetObject(resName);
			}
			return null;
		}
	}
}
